package com.qfedu.yanglao20app.guardian.service.impl;

import com.qfedu.yanglao20.common.utils.JwtUtils;
import com.qfedu.yanglao20.entity.guardian.Guardian;
import com.qfedu.yanglao20app.guardian.dao.GuardianDao;
import com.qfedu.yanglao20app.guardian.service.GuardianService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@Service
public class GuardianServiceImpl implements GuardianService {

    @Resource
    private GuardianDao guardianDao;

    @Override
    public String login(String name, String phone) {
        Guardian guardian = guardianDao.selectByName(name);
        if (guardian == null) {
            throw new RuntimeException("用户名不存在");
        }
        if (!phone.equals(guardian.getPhone())) {
            throw new RuntimeException("手机号错误");
        }

        Map<String, Object> map = new HashMap<>();
        map.put("agedId", guardian.getAgeId());
        String jwt = JwtUtils.createJwt(map);
        return jwt;

    }

}
